package company.baidu;

import java.util.Scanner;

public class BD1A {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt(), zeroNum = 0, fiveNum = 0;
        for (int i = 0; i < n; i++) {
            int num = sc.nextInt();
            if (num == 0)
                zeroNum++;
            else
                fiveNum++;
        }
        if (zeroNum == 0)
            System.out.println(-1);
        else if (fiveNum < 9)
            System.out.println(0);
        else {
            String fiveString = "555555555";
            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < fiveNum / 9; i++) {
                sb.append(fiveString);
            }
            for (int i = 0; i < zeroNum; i++) {
                sb.append(0);
            }
            System.out.println(sb);
        }
    }

}
